﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace carsitem.xiaoshou
{
    public partial class selltable : Form
    {
        //皮肤引擎对象
        Sunisoft.IrisSkin.SkinEngine se = null;
        string SkinName = "Calmness";
        public selltable()
        {
            InitializeComponent();
            //加载皮肤
            se = new Sunisoft.IrisSkin.SkinEngine();
            se.SkinAllForm = true;
            se.SkinFile = "skin/" + SkinName + ".ssk";
        }


        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void caozuo_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //声明控件变量
            string GoodsNumber = this.goodsbianBox.Text;
            string EmployeeID = this.comboxcaozuo.Text;
            string customerID = this.gubianBox.Text;
            string SellCount = this.moneyBox.Text;
            DateTime Selldate = this.dateTimePicker1.Value;
            string SellAddress = this.AddressBox9.Text;
            string Sellstate = this.comboxZT.Text;
            string Sellway = this.comboxFF.Text;
            string Note = this.noteBox.Text;
            //判断控件输入值是否合法
            zhengzebiaoda zda = new zhengzebiaoda();
            bool gb = zda.IsNumber(customerID);
            bool mb = zda.IsNumber(SellCount);
            bool gd = zda.IsNumber(GoodsNumber);
            if (gb==false&&gubianBox.Text!="")
            {
                MessageBox.Show("输入信息有误，请重新输入");
            }
            if (mb= false && moneyBox.Text!="")
            {
                MessageBox.Show("输入信息有误，请重新输入");
            }
            if (gd= false && goodsbianBox.Text!="")
            {
                MessageBox.Show("输入信息有误，请重新输入");
            }
            //判断控件值不同输入情况所执行的语句
            string sql = "";
            if (noteBox.Text!="")
            {
                sql = string.Format(@"insert Sell values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')", GoodsNumber, EmployeeID
            , customerID, SellCount, Selldate, SellAddress, Sellstate, Sellway, Note);
            }
            if (noteBox.Text=="")
            {
                sql = string.Format(@"insert Sell values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')", GoodsNumber, EmployeeID
             , customerID, SellCount, Selldate, SellAddress, Sellstate, Sellway,"");
            }
            DBHelper db = new DBHelper();

            bool result = db.ExcuteSql(sql);
            if (result == true)
            {
                MessageBox.Show("添加成功");
            }
            else
            {
                MessageBox.Show("添加失败");
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
            //下拉列表获取员工编号
            DBHelper db = new DBHelper();
            string sql = "select EmployeeID from Sell";
            DataTable one = db.GetDataTableBySql(sql);
            this.comboxcaozuo.ValueMember = "EmployeeID ";
            this.comboxcaozuo.DisplayMember = "EmployeeID";
            this.comboxcaozuo.DataSource = one;


        }

        private void tuichubt_Click(object sender, EventArgs e)
        {
            carsitem.MainInterface.MainInterfaceForm mainInterfaceForm = new carsitem.MainInterface.MainInterfaceForm();//把form1传给form2
            mainInterfaceForm.Show();
            this.Hide();//把自己隐藏了
        }

        private void comboxcaozuo_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void chongzhibt_Click(object sender, EventArgs e)
        {
            foreach (Control con in this.Controls)//遍历控件类集合
            {
                TextBox text = con as TextBox;//获取TextBox对象
                RadioButton rdo = con as RadioButton;//获取RadioButton对象
                CheckBox che = con as CheckBox;//获取CheckBox对象
                if (text != null)//文本框清空
                {
                    text.Text = "";
                }
                if (che != null)//多选框全不选
                {
                    che.Checked = false;
                }

            }
        }
    }
}